//
//  ADView.m
//  ImGuider
//
//  Created by 李陆涛 on 2018/5/21.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "ADView.h"

@interface ADView()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *label;

@end

@implementation ADView


- (void)awakeFromNib {
    
    [super awakeFromNib];
    [self setupUI];
    
}

- (instancetype)init {
    
    self = [super init];
    if (self) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI {
    
    UIEdgeInsets insets = UIEdgeInsetsMake(7, 10, 7, 10);
    // 指定为拉伸模式，伸缩后重新赋值
    UIImage *image = [[UIImage imageNamed:@"推荐"] resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    
    _imageView = [[UIImageView alloc] initWithImage:image];
    
    [self addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self);
    }];
    
    _label = [UILabel new];
    _label.font = Font(7);
    _label.textColor = [UIColor whiteColor];
    _label.textAlignment = NSTextAlignmentCenter;
    _label.adjustsFontSizeToFitWidth = YES;
    _label.minimumScaleFactor = 0.5;
    [self addSubview:_label];
    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_imageView.mas_left).offset(2);
        make.right.equalTo(_imageView.mas_right).offset(-2);
        make.top.equalTo(_imageView.mas_top);
        make.bottom.equalTo(_imageView.mas_bottom);
    }];
}

- (void)setText:(NSString *)text {
    
    if ([_text isEqualToString:text]) {
        return;
    }
    _text = text;
    self.label.text = text;
}

@end
